package com.flux.tms.tm${bean.numMain}srv.t${bean.numMain}${bean.numSub}.impl.dao;

import static org.mockito.ArgumentMatchers.any;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.mockito.InjectMocks;
import org.powermock.api.mockito.PowerMockito;
import org.testng.annotations.Test;

import com.alibaba.druid.util.JdbcConstants;
import com.flux.tms.tm${bean.numMain}srv.common.dao.CommonDao;
import com.flux.wmsv5.comobjs.LoginInfoObj;
import com.flux.tms.tm${bean.numMain}srv.t${bean.numMain}${bean.numSub}.impl.dao.${bean.fileName};


/**
*
* 单元测试类:  ${bean.fileName}
*
* 创建时间：${bean.dayTime}
*
* 修改时间：${bean.dayTime}
*
* @author YangSheng
*
* @version V1.0.0
*
*/
public class ${bean.fileName}Test extends CommonDao{
@InjectMocks
private ${bean.fileName} ${bean.fileName};

@Test
public void test() throws Exception {
        initLogin();
        initBizDataMap();
        ${bean.fileName} spy = PowerMockito.spy(${bean.fileName});
       // PowerMockito.doReturn(new StringBuffer()).when(spy, "randomOrderBySql", any(StringBuffer.class), any(Integer.class));

<#assign hasErr=false>
<#assign hasNomal=false>
<#if (bean.methods)?size !=0>
    <#list (bean.methods)! as method>
        <#if (method.mName)??>
            <#if ((method.mName)?contains("insert")||(method.mName)?contains("update")||(method.mName)?contains("del"))>
                <#if (method.mName)?contains("insert") >
        PowerMockito.doReturn(1).when(spy, "insertRow",any(LoginInfoObj.class), any(),any());
                </#if>
                <#if (method.mName)?contains("update") >
        PowerMockito.doReturn(1).when(spy, "editRow",any(LoginInfoObj.class), any(),any(),any());
                </#if>
                <#if (method.mName)?contains("del") >
        PowerMockito.doReturn(1).when(spy, "deleteRow",any(LoginInfoObj.class), any(),any());
                </#if>

        spy.${method.mName}(<#if (method.mParams)??><#list 0..((method.mParams)?size-1) as i><#if ((method.mParams)[i])?contains("Login") >loginInfoObj<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("List") >dataList<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("MapStr") >bizDataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("MapObj") >dataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String[]") >new String[]{"1"}<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String") >"ABC"<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("Boolean")||((method.mParams)[i])?contains("boolean") >true<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("int") >  0<#if i!= ((method.mParams)?size-1)>,</#if></#if></#list></#if>);

            <#else >
                <#if hasErr!=true>
        PowerMockito.doReturn(new HashMap<String, Object>()).when(spy, "queryForMap",any(LoginInfoObj.class), any(String.class),any(List.class),any(Boolean.class));
       // PowerMockito.doReturn(new HashMap<String, Object>()).when(spy, "queryForMap",any(LoginInfoObj.class), any(String.class),any(List.class));
                    <#assign hasErr=true>
                </#if>
                <#--PowerMockito.doReturn(new HashMap<String, Object>()).when(spy, "queryForMap",any(LoginInfoObj.class), any(String.class),any(List.class),any(Boolean.class));-->
         spy.${method.mName}(<#if (method.mParams)??><#list 0..((method.mParams)?size-1) as i> <#if ((method.mParams)[i])?contains("Login") >loginInfoObj<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("List") >dataList<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("MapStr") >bizDataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("Obj") >dataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String[]") >new String[]{"1"}<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String") >"ABC"<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("Boolean")||((method.mParams)[i])?contains("boolean") >true<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("int") >  0<#if i!= ((method.mParams)?size-1)>,</#if></#if></#list></#if>);
            </#if>
        </#if>
    </#list>
    <#list (bean.methods)! as method>
        <#if (method.mName)??>
        <#if ( (method.mName)?contains("insert")||(method.mName)?contains("update")||(method.mName)?contains("del")) >
        <#else >
            <#if hasNomal!=true>
        PowerMockito.doThrow(exception).when(spy, "queryForMap",any(LoginInfoObj.class), any(String.class),any(List.class),any(Boolean.class));
                <#assign hasNomal=true>
            </#if>

        spy.${method.mName}(<#if (method.mParams)??><#list 0..((method.mParams)?size-1) as i><#if ((method.mParams)[i])?contains("Login") >loginInfoObj<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("List") >dataList<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("MapStr") >bizDataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("MapObj") >dataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String[]") >new String[]{"1"}<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String") >"ABC"<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("Boolean")||((method.mParams)[i])?contains("boolean") >true<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("int") >  0<#if i!= ((method.mParams)?size-1)>,</#if></#if></#list></#if>);

        </#if>
        </#if>
    </#list>
</#if>
<#--PowerMockito.doReturn(1).when(spy, "insertRow",any(LoginInfoObj.class), any(),any());-->
<#--//        spy.insertAsnDocFee1H(loginInfoObj, bizDataMap);-->
<#--spy.insertRulDisZoneArea1H(loginInfoObj, bizDataMap);-->
<#--PowerMockito.doReturn("1").when(spy, "isnull",any(String.class),any(Integer.class));-->
<#--PowerMockito.doReturn(dbhelper).when(spy, "getDbHelper");-->
<#--PowerMockito.doReturn(JdbcConstants.MYSQL).when(spy, "getDbType");-->
<#--Map<String,String> tmpMapList = new HashMap<String, String>();-->
<#--Map<String,String> tmpMap = new HashMap<String, String>();-->
<#--PowerMockito.doReturn(tmpMap).when(spy, "queryForMap",any(LoginInfoObj.class),any(String.class),any(List.class),any(Boolean.class));-->
<#--PowerMockito.doReturn(tmpMapList).when(spy, "queryForList",any(LoginInfoObj.class),any(String.class),any(List.class),any(Boolean.class));-->
<#--PowerMockito.doReturn(1).when(spy, "insertRow",any(LoginInfoObj.class),any(Map.class),any(String.class));-->
<#--PowerMockito.doReturn(1).when(spy, "deleteRow",any(LoginInfoObj.class),any(String.class),any(LinkedHashMap.class));-->
<#--PowerMockito.doReturn(1).when(spy, "editRow",any(LoginInfoObj.class),any(Map.class),any(String.class),any(LinkedHashMap.class));-->
<#--PowerMockito.doReturn(1).when(spy, "update",any(LoginInfoObj.class),any(String.class),any(Object[].class));-->

}

@Override
protected CommonDao returnSubClass() {
return this;
}

@Override
protected void initSubLogin() {

}

@Override
protected void initSubBizDataMap() {

}


}
